Don't count custom compile scripts as targets.
authorRichard Diamond <wichard@vitalitystudios.com>
Tue, 11 Nov 2014 20:51:27 +0000 (14:51 -0600)
committerRichard Diamond <wichard@vitalitystudios.com>
Tue, 11 Nov 2014 20:51:27 +0000 (14:51 -0600)
src/cargo/util/toml.rs
tests/test_cargo_compile_custom_build.rs

index ead2c4f597a763a0026a06ce3dfca1eb1c1c99fc..ffdaf9b8a956d9e31e2ee81f50058377e1abb3f2 100644 (file)
@@ -118,7 +118,9 @@ pub fn to_manifest(contents: &[u8],
         Some(ref toml) => add_unused_keys(&mut manifest, toml, "".to_string()),
         None => {}
     }
-    if manifest.get_targets().len() == 0 {
+    if manifest.get_targets().iter()
+                           .filter(|t| !t.get_profile().is_custom_build() )
+                           .next().is_none() {
         return Err(human(format!("either a [lib] or [[bin]] section must \
                                   be present")))
     }
index cd441d049623f7edec5be661288125bf6c822612..056234dddce2e1d19b504cd36163977d47098094 100644 (file)
@@ -837,3 +837,19 @@ test!(release_with_build_script {
     assert_that(p.cargo_process("build").arg("-v").arg("--release"),
                 execs().with_status(0));
 })
+
+test!(build_script_only {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+              [project]
+              name = "foo"
+              version = "0.0.0"
+              authors = []
+              build = "build.rs"
+        "#)
+        .file("build.rs", r#"fn main() {}"#);
+    assert_that(p.cargo_process("build").arg("-v"),
+                execs().with_status(101)
+                       .with_stderr("either a [lib] or [[bin]] section must \
+                                     be present"));
+})